<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>DOM 查询</title>
  <style>
    li:hover {
      text-decoration: underline;
    }
    #a {
      color: lightcyan;
    }
    .box {
      width: 100px;
      height: 100px;
      line-height: 100px;
      border: 1px solid #000;
      display: inline-block;
      text-align: center;
    }
    .box:hover {
      background-color: #ddd;
    }
  </style>
</head>
<body>
  <ul id="a">
    <li>菠萝</li>
    <li>苹果</li>
    <li>梨</li>
  </ul>
  <div>
    <div class="box">1</div>
    <div class="box">2</div>
    <div class="box">3</div>
  </div>
</body>
<script>
  // 1. getElementById
  // var b = document.getElementById("b")
  // console.log(b.innerText);
  // 2. getElementsByTagName
  var lis = document.getElementsByTagName("li")
  console.log("3个li: ", lis);
  lis[0].onclick = function(event) {
    console.log("点击了第一个li");
  }
  // 3. 如果是div呢?
  // 3. getElementsByClassName
  var divs = document.getElementsByClassName("box")
  console.log(divs);
  divs[0].onclick = function(event) {
    console.log("点击了第一个div");
  }
  divs[1].onclick = function(event) {
    console.log("点击了第二个div");
  }
  divs[2].onclick = function(event) {
    console.log("点击了第三个div");
  }
</script>
</html>